package com.mallcloud.mall.app.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.mall.api.entity.MallPointsProductRedeemRecordModel;
import com.mallcloud.mall.mall.api.entity.MallPointsProductViewModel;
import com.mallcloud.mall.mall.api.entity.dto.ProPointsProductRedeem;
import com.mallcloud.mall.mall.api.entity.dto.ProRedeemItemBack;
import com.mallcloud.mall.mall.api.entity.vo.MallPointsProductRedeemRecordVO;
import com.mallcloud.mall.mall.api.entity.vo.MallPointsProductViewVO;
import com.mallcloud.mall.mall.service.MallPointsProductRedeemRecordService;
import com.mallcloud.mall.mall.service.MallPointsProductViewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Api(tags = "app-积分商品")
@RestController
@AllArgsConstructor
@RequestMapping("/app/pointsProduct")
public class AppPointsProductController {
	private final MallPointsProductViewService mallPointsProductViewService;
	private final MallPointsProductRedeemRecordService mallPointsRedeemRecordService;

    @ApiOperation("分页")
    @GetMapping("/page")
    public R<IPage<MallPointsProductViewVO>> getPage(Page page, MallPointsProductViewModel param) {
        return R.ok(mallPointsProductViewService.pagePointsProduct(page, param));
    }

	@ApiOperation("兑换")
	@PostMapping("/redeem")
	public R<ProPointsProductRedeem> redeemGoods(@RequestBody ProPointsProductRedeem entity) {
		mallPointsProductViewService.redeem(entity);
		return R.ok(entity);
	}

	@ApiOperation("兑换回滚")
	@PostMapping("/redeemRollBack")
	public R redeemRollBack(@RequestBody ProRedeemItemBack entity) {
		mallPointsProductViewService.redeemItemBack(entity);
		return R.ok();
	}

	@ApiOperation("积分商品兑换记录分页")
	@GetMapping("/redeemLogPage")
	public R<IPage<MallPointsProductRedeemRecordVO>> redeemLogPage(Page page, MallPointsProductRedeemRecordModel model) {
		return R.ok(mallPointsRedeemRecordService.pagePointsRedeemRecord(page, model));
	}
}